//
//  YNSMineController.m
//  HNBaseProject
//
//  Created by xujie on 2024/6/18.
//

#import "YNSMineController.h"
#import "YNSMineInfoController.h"
#import "YNSMineTableCell.h"
#import "YNSSetController.h"
@interface YNSMineController ()  <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *listTab;

@property (nonatomic, strong) MxPublicNav *nav;
@property (nonatomic, strong) UIImageView *headIconV;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *phoneLab;
@property (nonatomic, strong) ExpandButton *rightBtn;
@property (nonatomic, strong) UIButton *laywerBtn;
@property (nonatomic, strong) NSArray *iconArray;
@property (nonatomic, strong) NSArray *titleArray;

@end

@implementation YNSMineController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F7F8FA"];
    self.iconArray = @[@"mine_task",@"mine_sc",@"mine_ys",@"mine_yj",@"mine_gy",@"mine_sz"];
    self.titleArray = @[@"任务提醒",@"我的收藏",@"隐私协议",@"意见反馈",@"关于我们",@"设置",@""];
    [self createUI];
}

- (void)createUI {
    
    UIView *topBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScalHeight(270))];
    [self.view addSubview:topBg];
    [UIView setGradientView:topBg colors:@[[UIColor colorWithHexString:@"#E4EFFF"],[UIColor colorWithHexString:@"#F7F8FA"]] cornerRadius:0];
    
    self.nav = [[MxPublicNav alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kNavBarHeight)];
    self.nav.backgroundColor = [UIColor clearColor];
    self.nav.backButton.hidden = YES;
    self.nav.titleLab.text = @"我的";
    [self.view addSubview:self.nav];
    
    self.headIconV = [[UIImageView alloc] init];
    self.headIconV.contentMode = UIViewContentModeScaleAspectFill;
    self.headIconV.backgroundColor = UIColor.blackColor;
    self.headIconV.layer.cornerRadius = 8;
    self.headIconV.layer.masksToBounds = YES;
    [self.view addSubview:self.headIconV];
    
    self.nameLab = [[UILabel alloc] init];
    self.nameLab.textColor = [UIColor colorWithHexString:@"#121836"];
    self.nameLab.font = PFRFontMedium(22);
    self.nameLab.text = @"橙子";
    [self.view addSubview:self.nameLab];
    
    self.phoneLab = [[UILabel alloc] init];
    self.phoneLab.textColor = [UIColor colorWithHexString:@"#595958"];
    self.phoneLab.font = PFRFont(14);
    self.phoneLab.text = @"17755652713";
    [self.view addSubview:self.phoneLab];
    
    self.laywerBtn = [UIButton buttonWithType:0];
    [self.laywerBtn setTitle:@"律师" forState:0];
    [self.laywerBtn setBackgroundColor:[UIColor colorWithHexString:@"#0073FF"]];
    [self.laywerBtn setTitleColor:[UIColor dc_colorWithHexString:@"#FFFFFF"] forState:0];
    self.laywerBtn.titleLabel.font = PFRFont(12);
    [self.laywerBtn setImage:[UIImage imageNamed:@"lvs"] forState:0];
    self.laywerBtn.layer.cornerRadius = 4;
    self.laywerBtn.layer.masksToBounds = YES;
    [self.view addSubview:self.laywerBtn];
    
    self.rightBtn = [[ExpandButton alloc] init];
    [self.rightBtn setImage:[UIImage imageNamed:@"mine_right"] forState:UIControlStateNormal];
    [self.rightBtn addTarget:self action:@selector(gotoInfo) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.rightBtn];
    
    [self.headIconV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(64);
        make.left.offset(23);
        make.top.offset(kNavBarHeight+30);
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headIconV.mas_right).offset(17);
        make.top.mas_equalTo(self.headIconV.mas_top).offset(2);
        make.height.mas_equalTo(31);
    }];
    
    [self.phoneLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headIconV.mas_right).offset(17);
        make.top.mas_equalTo(self.nameLab.mas_bottom).offset(6);
    }];
    
    [self.laywerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLab.mas_right).offset(14);
        make.height.mas_equalTo(22);
        make.width.mas_equalTo(54);
        make.centerY.mas_equalTo(self.nameLab);
    }];
    
    [self.laywerBtn dc_buttonIconLeftWithSpacing:5];
    
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.headIconV);
        make.width.mas_equalTo(9);
        make.height.mas_equalTo(20);
        make.right.offset(-20);
    }];
    
    [self.view addSubview:self.listTab];
    [self.listTab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.mas_equalTo(self.headIconV.mas_bottom).offset(22);
        make.bottom.offset(-kTabBarHeight);
    }];
}

#pragma mark - ________ UITableView ________

- (UITableView *)listTab {
    
    if (nil == _listTab) {
        _listTab = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _listTab.backgroundColor = [UIColor clearColor];
        _listTab.separatorStyle = UITableViewCellSeparatorStyleNone;
        _listTab.delegate = self;
        _listTab.dataSource = self;
        _listTab.rowHeight = 74.0;
        _listTab.showsVerticalScrollIndicator = NO;
        _listTab.showsHorizontalScrollIndicator= NO;
        [_listTab registerClass:[YNSMineTableCell class] forCellReuseIdentifier:NSStringFromClass([YNSMineTableCell class])];
        if (@available(iOS 11.0, *)) {
            _listTab.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        if (@available(iOS 15.0, *)) {
            _listTab.sectionHeaderTopPadding = 0;
        }
    }
    return _listTab;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    YNSMineTableCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YNSMineTableCell class])];
    [cell reloadCellWithIcon:self.iconArray[indexPath.row] title:self.titleArray[indexPath.row]];
    return cell;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 5) {
        YNSSetController *setVc = [[YNSSetController alloc] init];
        [self.navigationController pushViewController:setVc animated:YES];
    }
}

- (void)gotoInfo {
    YNSMineInfoController *vc = [[YNSMineInfoController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
